-
Notifications
You must be signed in to change notification settings - Fork 578
Implement daily log rotation with improved log management #1541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Improvements to logging system: - Implement automatic daily log rotation at midnight - Keep 30 days of log history - Change default log location to /var/log/pgcli/pgcli.log - Automatic fallback to ~/.config/pgcli/log if no system permissions - Use TimedRotatingFileHandler for better log management - Log files formatted as: pgcli.log.YYYY-MM-DD Changes: - pgcli/main.py: Added logging.handlers import and updated initialize_logging() - pgcli/pgclirc: Updated documentation for new log behavior - pgcli/__init__.py: Bumped version to 4.3.7 - changelog.rst: Added Internal section entry 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Changed the log file rotation format from pgcli.log.YYYY-MM-DD to pgcli.YYYY-MM-DD.log for better file naming conventions. Changes: - pgcli/main.py: Updated suffix format and added logic to strip .log extension - pgcli/pgclirc: Updated documentation to reflect new format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
j-bennet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A user than needs log totation is the user that uses pgcli a lot.
We ❤️ this user.
Thank you for the PR!
dbaty
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary note: Contrbutions are much welcome. And I can see that you created other merge requests. Thanks a lot for wanting to move pgcli forward. ❤️ I am not the only maintainer (and I am not the most active one), so this is just my opinion. @j-bennet : I'd welcome your take on this.
tl;dr : I am not convinced that pgcli needs this feature. I am not in favor of merging this feature.
Do you have other examples of user-controlled softwares (not servers, but rather TUIs and such) that rotate their logs ? I can't think of any that does (or does it by default), off the top of my head. In fact, I would find it odd that the default behaviour of pgcli would be to rotate logs. (Also, it is a breaking change. Someone somewhere may rely on the fact that logs are kept forever. I don't think it's a particularly unusual expectation for user-controlled software.)
I am not saying that it's completely useless. I am not saying that it adds a considerable amount of hard-to-maintain code. But it is code that we'll have to maintain. It's a feature that someone will want to deactivate (I know I do!), or want to tweak ("I want to keep 2 months of logs instead of 30 days"). That will add up in the configuration file and, obviously, in the code itself. All that must be weighted against the need for rotating logs.
| if log_file == "default": | ||
| log_file = config_location() + "log" | ||
| # Try /var/log/pgcli first, fallback to user config dir if no permissions | ||
| default_system_log = "/var/log/pgcli/pgcli.log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it odd to try this location first before what the user specified in their configuration file. If (and it's a big "if", see below) we want to try this /var/log/ location, I suggest that we do it like this:
- Look at the configuration file.
- If the user specified a custom location, use it.
- Otherwise, try
/var/log/... - If that fails, use default location in user directory.
But... I don't quite see the point in trying /var/log/:
- the user is very unlikely to have access to
/var/log/(unless one runs pgcli as root, which is questionable); - in my experience (for what it's worth!),
/var/log/is usually for machine-wide software (servers, system tools, etc.), not user-controlled software.
All in all, I am not in favour of storing logs in /var/log/.
| handler = logging.NullHandler() | ||
| else: | ||
| handler = logging.FileHandler(os.path.expanduser(log_file)) | ||
| # Use TimedRotatingFileHandler for daily log rotation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a user, I do not want pgcli log files to be rotated (I'll explain more in another comment). How can I do that?
Summary
This PR implements automatic daily log rotation and improves the default log location for pgcli.
Changes
1. Daily Log Rotation
TimedRotatingFileHandlerpgcli.YYYY-MM-DD.log2. Improved Default Log Location
/var/log/pgcli/pgcli.log(system-wide logging)~/.config/pgcli/logif user lacks system permissions3. Updated Documentation
pgclircconfiguration file with new log behaviorchangelog.rstTechnical Details
Before:
~/.config/pgcli/logAfter:
pgcli.YYYY-MM-DD.logFiles Modified
pgcli/main.py: Addedlogging.handlersimport and updatedinitialize_logging()functionpgcli/pgclirc: Updated log_file documentationchangelog.rst: Added entry for log rotation featureTesting
Tested manually:
Backward Compatibility
log_filesettings in config will continue to work as beforeBenefits
/var/loglocation when possibleMade with ❤️ and 🤖 Claude Code